<!-- 任务执行情况 -->
<template>
  <el-dialog :title="titleName" :visible.sync="dialogTableVisible" @close="$emit('update:visible',false)"
             :close-on-click-modal="false">
    <el-form label-width="100px">
      <el-form-item label="任务名称:" prop="return_time" v-if="commonType==1||commonType==3">
        {{detail.name}}
      </el-form-item>
      <el-form-item label="任务当前状态:" v-if="commonType==1||commonType==3">
        <div class="c-danger">
          <span>
           {{detail.is_end}}
          </span>
        </div>
      </el-form-item>
      <el-form-item label="任务执行者:" v-if="commonType==2">
        <div class="c-danger">
          <span>
            {{detail.taskName}}
          </span>
        </div>
      </el-form-item>
      <el-form-item label="任务回复附件:" v-if="commonType==1">
        <el-upload
                class="upload-demo"
                :action="$uploadImg"
                :on-remove="handleDocRemove"
                :on-success="handleDocSuccess"
                :before-upload="beforeAvatarDocUpload"
                accept=".doc,.docx,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document"
                multiple
                :limit="1">
          <el-button size="small" class="el-icon-upload">点击上传相应文件</el-button>
          <div slot="tip" class="el-upload__tip">上传word文件</div>
        </el-upload>
      </el-form-item>
      <!--<el-form-item :label="commonType==1?'任务回复图片:':'任务评论图片:'">-->
      <el-form-item label="任务回复图片">
        <el-upload
                :action="$uploadImg"
                list-type="picture-card"
                accept=".jpg,.jpeg,.png"
                :limit="9"
                :on-success="handleSuccess"
                :on-remove="handleRemove">
          <i class="el-icon-plus"></i>
        </el-upload>
        (图片大小不超过2M,支持jpg、png格式，最多可上传9张)
      </el-form-item>
      <el-form-item label="任务回复描述" prop="return_time">
        <!--<el-form-item :label="commonType==1?'任务回复描述:':'任务评论描述:'" prop="return_time">-->
        <el-input v-model="textareaVal" placeholder="填写任务回复进程" type="textarea"></el-input>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click.native="dialogTableVisible = false" size="small">取 消</el-button>
      <el-button type="primary" @click="httpSubmit" size="small">确 定</el-button>
    </div>
  </el-dialog>
</template>
<script>
  import api from '@/utils/api.js'

  export default {
    name: 'taskListDialog',
    props: ['visible', 'detail', 'pageType', 'commonType', 'taskUserId'], // taskUserId 评论列表id
    watch: {
      visible () {
        this.dialogTableVisible = this.visible
      }
    },
    data () {
      return {
        dialogTableVisible: this.visible,
        textareaVal: '',
        picImg: [],
        titleName: '',
        file: ''
      }
    },
    created () {
      // 1 commonType 回复类型，1 完成 2 管理员评论 3日志报告
      if (this.commonType === 1) {
        this.titleName = '完成任务提交日志'
      } else if (this.commonType === 2) {
        this.titleName = '发布者评论回复日志'
      } else if (this.commonType === 3) {
        this.titleName = '任务日志报告'
      }
    },
    methods: {
      // 提交任务信息
      httpSubmit () {
        let data_ = {}
        // 1 commonType 回复类型，1 完成 2 管理员评论 3日志报告
        if (!this.textareaVal) {
          this.$message.error('请填写回复内容')
          return
        }
        let url_ = api.admin_report
        if (this.commonType === 1) {
          data_.file = this.file
        }
        if (this.commonType === 3) {
          url_ = api.admin_reportNotEnd
        }
        if (this.commonType === 2) {
          url_ = api.admin_evaluate
          data_.task_user_id = this.detail.id
          data_.id = this.taskUserId
          data_.evaluate = this.textareaVal
          data_.evaluate_pic = this.picImg.join(',')
        } else {
          data_.reply = this.textareaVal
          data_.id = this.detail.id
          data_.reply_pic = this.picImg.join(',')
          data_.task_user_id = this.taskUserId
        }
        console.log(data_)
        this.$post(url_, data_).then((response) => {
          console.log('数据：', response)
          if (response.code === 0) {
            this.$message({
              message: '提交成功',
              type: 'success'
            })
            this.$emit('getUser', 'comment')
            this.dialogTableVisible = false
            this.textareaVal = ''
          } else {
            this.$message.error(response.msg)
          }
        }).catch((err) => {
          console.log(err)
        })
      },
      handleRemove (file, fileList) {
        let num = this.picImg.indexOf(file.response.data.name)
        this.picImg.splice(num, 1)
      },
      handleSuccess (response, file, fileList) {
        console.log('成功了:', response, file, fileList)
        this.picImg.push(response.data.name)
      },
      beforeAvatarDocUpload (file) {
        console.log('上传数据excel：', file)
        // const isLt2M = file.size / 1024 / 1024 < 2
        // if (!isLt2M) {
        //   this.$message.error('上传头像图片大小不能超过 2MB!')
        // }
        // return isLt2M
      },
      handleDocSuccess (response) {
        this.file = response.data.pic
      },
      handleDocRemove (file, fileList) {
        console.log('移除', file, fileList)
        this.file = ''
      }
    }
  }
</script>
